package com.mask.roll.edu.controller;


import com.mask.roll.common.code.ServiceEnums;
import com.mask.roll.common.constant.RollConstants;
import com.mask.roll.common.util.RollResponse;
import com.mask.roll.edu.entity.Chapter;
import com.mask.roll.edu.entity.VO.chapter.ChapterVO;
import com.mask.roll.edu.service.ChapterService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.apache.ibatis.annotations.Delete;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 课程 前端控制器
 * </p>
 *
 * @author hx
 * @since 2021-10-23
 */
@RestController
@RequestMapping("/edu/chapter")
@Api(tags = "课程章节管理")
public class ChapterController {

    @Autowired
    private ChapterService chapterService;

    /**
     * 获取课程大纲列表
     * @return
     */
    @GetMapping("/get/chapter/video/{courseId}")
    @ApiOperation("获取课程大纲列表")
    public RollResponse getChapterVideo(@ApiParam("课程id") @PathVariable String courseId){
        List<ChapterVO> list = chapterService.getChapterVideoByCourseId(courseId);
        return RollResponse.result(ServiceEnums.CHAPTER_VIDEO_GET.getCode(),
                RollConstants.SUCCESS,ServiceEnums.CHAPTER_VIDEO_GET.getMessage(),list);
    }

    /**
     * 添加课程章节
     * @param chapter
     * @return
     */
    @PostMapping("/add")
    @ApiOperation("添加课程章节")
    public RollResponse addChapter(@RequestBody Chapter chapter){
        chapterService.save(chapter);
        return RollResponse.result(ServiceEnums.CHAPTER_ADD_SUCCESS.getCode(),
                RollConstants.SUCCESS,ServiceEnums.CHAPTER_ADD_SUCCESS.getMessage());
    }


    /**
     * 根据章节id查询
     * @param chapterId
     * @return
     */
    @GetMapping("/get/{chapterId}")
    @ApiOperation("根据章节id查询")
    public RollResponse getChapter(@ApiParam("章节id") @PathVariable String chapterId){
        Chapter chapter = chapterService.getById(chapterId);
        return RollResponse.result(ServiceEnums.CHAPTER_SELECT_SUCCESS.getCode(),
                RollConstants.SUCCESS,ServiceEnums.CHAPTER_SELECT_SUCCESS.getMessage(),chapter);
    }

    /**
     * 修改章节信息
     * @param chapter
     * @return
     */
    @PostMapping("/update")
    @ApiOperation("修改章节信息")
    public RollResponse updateChapter(@RequestBody Chapter chapter){
        chapterService.updateById(chapter);
        return RollResponse.result(ServiceEnums.CHAPTER_UPDATE_SUCCESS.getCode(),
                RollConstants.SUCCESS,ServiceEnums.CHAPTER_UPDATE_SUCCESS.getMessage());
    }


    /**
     * 删除章节
     * @param chapterId
     * @return
     */
    @DeleteMapping("/delete/{chapterId}")
    @ApiOperation("删除章节")
    public RollResponse deleteChapter(@ApiParam("章节id") @PathVariable String chapterId){
        chapterService.deleteChapter(chapterId);
        return RollResponse.result(ServiceEnums.CHAPTER_DELETE_SUCCESS.getCode(),
                RollConstants.SUCCESS,ServiceEnums.CHAPTER_DELETE_SUCCESS.getMessage());
    }


}

